package com.treasure.service.user.service.impl;

import com.treasure.service.domain.TUserAccount;
import com.treasure.service.mapper.TAccountChangeLogMapper;
import com.treasure.service.mapper.TUserAccountMapper;
import com.treasure.service.user.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 用户账户管理
 *
 * @author <a href="mailto:panxinwen@yingu.com">Pan Xinwen</a>
 * @version 1.0 2018-06-23 16:01
 */
@Service
public class UserAccountServiceImpl implements UserAccountService {

    @Autowired
    private TUserAccountMapper tUserAccountMapper;

    @Autowired
    private TAccountChangeLogMapper tAccountChangeLogMapper;

    @Override
    public int createUserAccount(Long userId) {

        TUserAccount userAccount = new TUserAccount();
        userAccount.setAddTime(new Date());
        userAccount.setReward(0l);
        userAccount.setTotalAssets(0l);
        userAccount.setTotalBalance(0l);
        userAccount.setModTime(new Date());
        userAccount.setUserId(userId);

        return tUserAccountMapper.insert(userAccount);
    }

    @Override
    public TUserAccount getUserAccount(Long userId) {
        return tUserAccountMapper.selectByPrimaryKey(userId);
    }

}
